/**
 * ----------------------------------------------------------------------------
 * Copyright Jens Konopka
 * 
 * Alle Rechte vorbehalten.
 * Licence: Apache 2.0
 * ----------------------------------------------------------------------------
 *
 * created on 06.03.2012 by jk
 */
package de.sql.toolkit.generator;

import java.io.File;

import de.sql.toolkit.model.Column;
import de.sql.toolkit.model.Table;
import de.sql.toolkit.util.StringUtil;

/**
 * @author jk
 * 
 */
public class CSharpGetSetMethodGenerator extends AbstractJvModelGenerator {

	/**
	 * 
	 */
	private static final long serialVersionUID = -2950511889895235779L;

	/**
	 * @param dstPath
	 * @param table
	 */
	public CSharpGetSetMethodGenerator(File dstPath, Table table) {
		super(dstPath, table);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see de.sql.toolkit.generator.IGenerator#generate()
	 */
	@Override
	public String generate() throws Exception {
		final StringBuilder content = new StringBuilder();
		for (final Column column : getTable().getColumns()) {
			final String type = getFieldType(column.getType(), column.getNullable());
			content.append("\t\tpublic ");
			content.append(type);
			content.append(" ");
			content.append(StringUtil.upperCaseFirstLetters(column.getName()));
			content.append("\n\t\t{\n");
			content.append(generateGet(column));
			content.append(generateSet(column));
			content.append("\t\t}\n\n");
		}
		return content.toString();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see de.sql.toolkit.generator.AbstractJvModelGenerator#getFieldTypeProgrammingLanguageKey()
	 */
	@Override
	protected String getFieldTypeProgrammingLanguageKey() {
		return "csharp";
	}

	/**
	 * @return
	 */
	public String generateGet(final Column column) {
		final StringBuilder sb = new StringBuilder();
		sb.append("\t\t\tget\n\t\t\t{\n");
		sb.append("\t\t\t\treturn this.");
		sb.append(prepareName(column.getName()));
		sb.append(";\n\t\t\t}\n");
		return sb.toString();
	}

	/**
	 * @return
	 */
	public String generateSet(final Column column) {
		final StringBuilder sb = new StringBuilder();
		sb.append("\t\t\tget\n\t\t\t{\n");
		sb.append("\t\t\t\tthis.");
		sb.append(prepareName(column.getName()));
		sb.append(" = value;\n\t\t\t}\n");
		return sb.toString();
	}

}
